package com.wicket.okrapp.base.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wicket.okrapp.base.service.MOmsUnstructuredDataFolderService;
import com.wicket.okrapp.base.service.dto.req.QueryDataFolderDetailReq;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrapp.dal.mapper.mbg.OmsUnstructuredDataFolderMapper;
import com.wicket.okrapp.dal.po.mbg.OmsUnstructuredDataFolder;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MOmsUnstructuredDataFolderServiceImpl
        extends ServiceImpl<OmsUnstructuredDataFolderMapper, OmsUnstructuredDataFolder>
        implements MOmsUnstructuredDataFolderService {

    @Autowired
    OmsUnstructuredDataFolderMapper omsUnstructuredDataFolderMapper;

    /**
     * 2-7-02删除文件夹
     */
    @Trace(operationName = "2-7-02删除文件夹")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteDataFolder(String unstructuredDataFolderId) {

        return super.removeById(unstructuredDataFolderId);
    }

    /**
     * 2-7-02查询文件夹详情
     */
    @Trace(operationName = "2-7-02查询文件夹详情")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public OmsUnstructuredDataFolder queryDataFolderDetail(QueryDataFolderDetailReq reqDto) {

        try {

            Map<String, Object> columnMap = CommonFunctionHelper.objectToMap(reqDto);
            List<OmsUnstructuredDataFolder> retList = (List<OmsUnstructuredDataFolder>) super.listByMap(columnMap);
            if (retList == null || retList.size() <= 0) return null;
            OmsUnstructuredDataFolder ret = retList.get(0);

            return ret;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }

    }

    /**
     * 2-7-02新增文件夹
     */
    @Trace(operationName = "2-7-02新增文件夹")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addDataFolder(OmsUnstructuredDataFolder omsUnstructuredDataFolder) {
        omsUnstructuredDataFolder.setUnstructuredDataFolderId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
        omsUnstructuredDataFolder.setIsArchive("FALSE");
        omsUnstructuredDataFolder.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsUnstructuredDataFolder.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsUnstructuredDataFolder.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsUnstructuredDataFolder.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsUnstructuredDataFolder.setIsValid("FALSE");
        omsUnstructuredDataFolder.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
        omsUnstructuredDataFolder.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
        if (super.save(omsUnstructuredDataFolder)) {
            return omsUnstructuredDataFolder.getUnstructuredDataFolderId();
        } else {
            return "-1";
        }

    }
}
